# -*- coding: utf-8 -*-
# filename: handle.py

import web
import json
from configcenter import configCenter
class bulletAvailable(object):
    def GET(self):
        try:
            web.header("Access-Control-Allow-Origin", "*")
            web.header('content-type','text/json')
            cc = configCenter()
            config = cc.getConfig()
            host = config.get("global", "ip")
            port = config.get("global", "port")
            user = config.get("global", "user")
            pw = config.get("global", "password")
            database = config.get("global", "database")
            db = web.database(dbn='mysql', host=host, port=int(port), user=user, pw=pw, db=database)
            persons = db.select('bullet',where="passes='no'")
            pdata = []
            for person in persons:
                pdata.append(person.message)
		db.update('bullet', where="mobile="+person.mobile, passes="yes")
            datadict = {}
            datadict['data'] = pdata
            datadict['result'] = True
            return json.dumps(datadict)
        except Exception as e:
            return e.args

